package com.lazyking.nio.discard;

import io.netty.buffer.ByteBuf;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.util.ReferenceCountUtil;

import java.nio.charset.Charset;

public class DiscardServerHandler extends ChannelInboundHandlerAdapter {
//    @Override
//    public void channelRead(ChannelHandlerContext ctx,Object msg){
//        ByteBuf buf = (ByteBuf) msg;
//        try {
//            while(buf.isReadable()){
//                char c = (char) buf.readByte();
//                System.out.println(c);
//                System.out.flush();
//            }
//        }finally {
//            ReferenceCountUtil.release(buf);
//        }
//    }
    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {

        ctx.writeAndFlush(msg);
    }
    @Override
    public void exceptionCaught(ChannelHandlerContext ctx,Throwable cause){
        cause.printStackTrace();
        ctx.close();
    }
}
